<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="租户" prop="sellerId">
      <el-input v-model="dataForm.sellerId" placeholder="租户"></el-input>
    </el-form-item>
    <el-form-item label="是否抹零1抹2不" prop="zeroStatus">
      <el-input v-model="dataForm.zeroStatus" placeholder="是否抹零1抹2不"></el-input>
    </el-form-item>
    <el-form-item label="四舍五入到元" prop="ruleNoe">
      <el-input v-model="dataForm.ruleNoe" placeholder="四舍五入到元"></el-input>
    </el-form-item>
    <el-form-item label="向下抹零到元" prop="ruleTwo">
      <el-input v-model="dataForm.ruleTwo" placeholder="向下抹零到元"></el-input>
    </el-form-item>
    <el-form-item label="向上抹零到元" prop="ruleThree">
      <el-input v-model="dataForm.ruleThree" placeholder="向上抹零到元"></el-input>
    </el-form-item>
    <el-form-item label="四舍五入到角" prop="ruleFour">
      <el-input v-model="dataForm.ruleFour" placeholder="四舍五入到角"></el-input>
    </el-form-item>
    <el-form-item label="向下抹零到角" prop="ruleFive">
      <el-input v-model="dataForm.ruleFive" placeholder="向下抹零到角"></el-input>
    </el-form-item>
    <el-form-item label="向上抹零到角" prop="ruleSix">
      <el-input v-model="dataForm.ruleSix" placeholder="向上抹零到角"></el-input>
    </el-form-item>
    <el-form-item label="时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="时间"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :disabled="disabledSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
				disabledSubmit:false,
        dataForm: {
          id: 0,
          sellerId: '',
          zeroStatus: '',
          ruleNoe: '',
          ruleTwo: '',
          ruleThree: '',
          ruleFour: '',
          ruleFive: '',
          ruleSix: '',
          createTime: '',
          remark: ''
        },
        dataRule: {
          sellerId: [
            { required: true, message: '租户不能为空', trigger: 'blur' }
          ],
          zeroStatus: [
            { required: true, message: '是否抹零1抹2不不能为空', trigger: 'blur' }
          ],
          ruleNoe: [
            { required: true, message: '四舍五入到元不能为空', trigger: 'blur' }
          ],
          ruleTwo: [
            { required: true, message: '向下抹零到元不能为空', trigger: 'blur' }
          ],
          ruleThree: [
            { required: true, message: '向上抹零到元不能为空', trigger: 'blur' }
          ],
          ruleFour: [
            { required: true, message: '四舍五入到角不能为空', trigger: 'blur' }
          ],
          ruleFive: [
            { required: true, message: '向下抹零到角不能为空', trigger: 'blur' }
          ],
          ruleSix: [
            { required: true, message: '向上抹零到角不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '时间不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstorewipezerorule/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sellerId = data.tStoreWipeZeroRule.sellerId
                this.dataForm.zeroStatus = data.tStoreWipeZeroRule.zeroStatus
                this.dataForm.ruleNoe = data.tStoreWipeZeroRule.ruleNoe
                this.dataForm.ruleTwo = data.tStoreWipeZeroRule.ruleTwo
                this.dataForm.ruleThree = data.tStoreWipeZeroRule.ruleThree
                this.dataForm.ruleFour = data.tStoreWipeZeroRule.ruleFour
                this.dataForm.ruleFive = data.tStoreWipeZeroRule.ruleFive
                this.dataForm.ruleSix = data.tStoreWipeZeroRule.ruleSix
                this.dataForm.createTime = data.tStoreWipeZeroRule.createTime
                this.dataForm.remark = data.tStoreWipeZeroRule.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
				this.disabledSubmit = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstorewipezerorule/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'zeroStatus': this.dataForm.zeroStatus,
                'ruleNoe': this.dataForm.ruleNoe,
                'ruleTwo': this.dataForm.ruleTwo,
                'ruleThree': this.dataForm.ruleThree,
                'ruleFour': this.dataForm.ruleFour,
                'ruleFive': this.dataForm.ruleFive,
                'ruleSix': this.dataForm.ruleSix,
                'createTime': this.dataForm.createTime,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '设置抹零后需要重新登录才能生效',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
										this.disabledSubmit = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
